<?php
$dsn="mysql:Server=127.0.0.1;dbname=blog";
$db= new PDO($dsn, "root", "123456");
$db ->exec("set names utf8mb4");

$addTime =time();
$updateTime =$addTime;

$sql ="insert into article (article_title, category_id, intro, article_content,update_time, add_time)
        values ('$articleTitle', '$categoryId', '$intro', '$articleContent', '$updateTime', '$addTime')";
$result =$db->exec($sql);

if ($result) {
    $log = [
        'action' => 'article_add',
        'content' => '增加文件成功',
        'time' => date("Y-m-d H:i:s", time()),
        'ip' => $_SERVER['REMOTE_ADDR'],
        'article_title' => $articleTitle,
        'category_id' => $categoryId,
        'intro' => $intro,
//        'content' => $content,
    ];
    $file = fopen("./logs/" . date("Y-m-d") . ".txt", 'a+');
    if ($file) {
        fwrite($file, json_encode($log, JSON_UNESCAPED_UNICODE) . PHP_EOL);
        fclose($file);
    } else {
        echo "打开文件错误";
        exit();
    }
}